<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" >
            <div class="layui-form-item">
                <label for="" class="layui-form-label">队列号码</label>
                <div class="layui-input-block">
                    <input type="text" name="extension" placeholder="请输入队列号码，如：666666" lay-verify="required|number" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">队列名称</label>
                <div class="layui-input-block">
                    <input type="text" name="descr" placeholder="请输入队列名称，如：test" lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">队列成员</label>
                <div class="layui-input-block">
                    <textarea name="members" id="members" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">选择成员</label>
                <div class="layui-input-block">
                    <select lay-filter="getMember">
                        <option value=""></option>
                        <?php foreach ($members as $m) { ?>
                            <option value="<?php echo $m['extension'] ?>"><?php echo $m['extension'] ?>（<?php echo $m['name']; ?>）</option>
                        <?php } ?>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">响铃模式</label>
                <div class="layui-input-block">
                    <select name="strategy">
                        <?php foreach (Yii::$app->params['ring_strategy'] as $k=>$v) { ?>
                            <option value="<?php echo $k; ?>"><?php echo $v; ?></option>
                        <?php } ?>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">跳过繁忙</label>
                <div class="layui-input-block">
                    <select name="cwignore">
                        <?php foreach (Yii::$app->params['cwignore'] as $k=>$v) { ?>
                            <option value="<?php echo $k; ?>"><?php echo $v; ?></option>
                        <?php } ?>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">录音模式</label>
                <div class="layui-input-block">
                    <select name="monitor_type">
                        <option value="">包括振铃</option>
                        <option value="b">接通后录音</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">录音格式</label>
                <div class="layui-input-block">
                    <select name="monitor-format">
                        <option value="">不录音</option>
                        <?php foreach (Yii::$app->params['monitor-format'] as $k=>$v) { ?>
                            <option value="<?php echo $k; ?>"><?php echo $v; ?></option>
                        <?php } ?>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="submitForm">确认</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>


<?php
$url = yii\helpers\Url::to(['create']);

$js = <<<JS
    layui.use(['form','element','table', 'layer'],function() {
        var form = layui.form;  
        var element = layui.element;  
        var table = layui.table;  
        var layer = layui.layer;  
        
        window.removeReg = function (obj){
            $(obj).parent("div").remove()
        }
        
        //监听select
        form.on('select(getMember)', function(data){
            $("#members").val($("#members").val()+data.value+","+"0\\n");
            $(data.elem).find("option[value='"+data.value+"']").attr("disabled",true)
            form.render("select");
        }); 
        
        //监听表单提交
        form.on('submit(submitForm)',function(data) {
            var index = layer.load()
            var where = data.field
            $.post("{$url}",where,function(res) {
                layer.close(index)
                layer.msg(res.msg,{},function() {
                    if (res.code==0){
                        location.reload();
                    }   
                })   
            })
            return false
        })
        
    });
JS;
$this->registerJs($js);
